# Reference: <https://postmarketos.org/devicepkg>
# Maintainer: Raymond Hackley <wonderfulShrineMaidenOfParadise@postmarketos.org>
pkgname=device-samsung-fortuna
pkgdesc="Samsung Galaxy Grand Prime"
pkgver=5
pkgrel=1
url="https://postmarketos.org"
license="MIT"
arch="aarch64"
options="!check !archcheck"
depends="
	mkbootimg
	postmarketos-base
	soc-qcom-msm8916
	soc-qcom-msm8916-rproc
"
makedepends="devicepkg-dev"
source="deviceinfo modules-initfs"
subpackages="
	$pkgname-nonfree-firmware:nonfree_firmware
	$pkgname-kernel-fortuna3g:kernel_fortuna3g
	$pkgname-kernel-gprimeltecan:kernel_fortuna3g
	$pkgname-kernel-grandprimelte:kernel_grandprimelte
"
_variants="
	fortuna3g
	gprimeltecan
	grandprimelte
"

for _variant in $_variants; do
	subpackages="
		$subpackages
		${pkgname%-fortuna}-$_variant-nonfree-firmware:nonfree_firmware_$_variant
	"
done

_pmb_select="soc-qcom-msm8916-rproc"

build() {
	devicepkg_build $startdir $pkgname
}

package() {
	devicepkg_package $startdir $pkgname
}

kernel_fortuna3g() {
	pkgdesc="$pkgdesc (SM-G530H)"
	depends="$pkgname=$pkgver-r$pkgrel linux-postmarketos-qcom-msm8916"

	# Backwards compatibility for old device package name
	local _old_pkgname="device-samsung-fortuna3g"
	replaces="$_old_pkgname"
	provides="$_old_pkgname=$pkgver-r$pkgrel"

	devicepkg_subpackage_kernel $startdir $pkgname $subpkgname
}

kernel_gprimeltecan() {
	pkgdesc="$pkgdesc (SM-G530W)"
	depends="$pkgname=$pkgver-r$pkgrel linux-postmarketos-qcom-msm8916"

	# Backwards compatibility for old device package name
	local _old_pkgname="device-samsung-gprimeltecan"
	replaces="$_old_pkgname"
	provides="$_old_pkgname=$pkgver-r$pkgrel"

	devicepkg_subpackage_kernel $startdir $pkgname $subpkgname
}

kernel_grandprimelte() {
	pkgdesc="$pkgdesc (SM-G530FZ)"
	depends="$pkgname=$pkgver-r$pkgrel linux-postmarketos-qcom-msm8916"

	# Backwards compatibility for old device package name
	local _old_pkgname="device-samsung-gprimeltexx"
	replaces="$_old_pkgname"
	provides="$_old_pkgname=$pkgver-r$pkgrel"

	devicepkg_subpackage_kernel $startdir $pkgname $subpkgname
}

nonfree_firmware() {
	pkgdesc="GPU/WiFi/BT/Modem/Video firmware"
	depends="firmware-qcom-adreno-a300 msm-firmware-loader"

	mkdir "$subpkgdir"
}

nonfree_firmware_fortuna3g() {
	local _variant="fortuna3g"
	pkgdesc="WiFi/BT firmware configuration (SM-G530H)"
	depends="firmware-samsung-$_variant-wcnss-nv"
	install_if="
		$pkgname-kernel-$_variant=$pkgver-r$pkgrel
		$pkgname-nonfree-firmware=$pkgver-r$pkgrel
	"

	mkdir "$subpkgdir"
}

nonfree_firmware_gprimeltecan() {
	local _variant="gprimeltecan"
	pkgdesc="WiFi/BT firmware configuration (SM-G530W)"
	depends="firmware-samsung-$_variant-wcnss-nv"
	install_if="
		$pkgname-kernel-$_variant=$pkgver-r$pkgrel
		$pkgname-nonfree-firmware=$pkgver-r$pkgrel
	"

	mkdir "$subpkgdir"
}

nonfree_firmware_grandprimelte() {
	local _variant="grandprimelte"
	pkgdesc="WiFi/BT firmware configuration (SM-G530FZ)"
	depends="firmware-samsung-$_variant-wcnss-nv"
	install_if="
		$pkgname-kernel-$_variant=$pkgver-r$pkgrel
		$pkgname-nonfree-firmware=$pkgver-r$pkgrel
	"

	# Backwards compatibility for old device package name
	local _old_pkgname="device-samsung-gprimeltexx-nonfree-firmware"
	provides="$_old_pkgname=$pkgver-r$pkgrel"

	mkdir "$subpkgdir"
}

sha512sums="
c95156cbaee8dca8600ffbc1143575fe4b5c9eaf09545f265d1950f0f36e91175deff2789176629f5171309477c63ae4a62de3ff185f131abe226202f0c756ba  deviceinfo
02b6d383149ba2ec3a31b206767be7ead31d9f0e7ee5cab11047000c53ccad387a118cbddb06093bca5cae3e82f884c02194de47b8e7a9c76102ac46506bb111  modules-initfs
"
